home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kdeprint / kmprinter.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  9.1 KB  |  237 lines

  1. /*
  2.  *  This file is part of the KDE libraries
  3.  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License version 2 as published by the Free Software Foundation.
  8.  *
  9.  *  This library is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.  *  Library General Public License for more details.
  13.  *
  14.  *  You should have received a copy of the GNU Library General Public License
  15.  *  along with this library; see the file COPYING.LIB.  If not, write to
  16.  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.  *  Boston, MA 02110-1301, USA.
  18.  **/
  19.  
  20. #ifndef KMPRINTER_H
  21. #define KMPRINTER_H
  22.  
  23. #if !defined( _KDEPRINT_COMPILE ) && defined( __GNUC__ )
  24. #warning internal header, do not use except if you are a KDEPrint developer
  25. #endif
  26.  
  27. #include <qstring.h>
  28. #include <qstringlist.h>
  29. #include <qptrlist.h>
  30. #include <kurl.h>
  31. #include <qmap.h>
  32. #include <kdeprint/kmobject.h>
  33.  
  34. class KMDBEntry;
  35. class DrMain;
  36. class KPrinter;
  37. class QWidget;
  38.  
  39. /**
  40.  * @internal
  41.  * This class is internal to KDEPrint and is not intended to be
  42.  * used outside it. Please do not make use of this header, except
  43.  * if you're a KDEPrint developer. The API might change in the
  44.  * future and binary compatibility might be broken.
  45.  */
  46. class KDEPRINT_EXPORT KMPrinter : public KMObject
  47. {
  48. public:
  49.     enum PrinterType {
  50.         Printer     = 0x01,
  51.         Class    = 0x02,
  52.         Implicit = 0x04,
  53.         Virtual  = 0x08,
  54.         Remote   = 0x10,
  55.         Invalid  = 0x20,
  56.         Special  = 0x40
  57.     };
  58.     enum PrinterState {
  59.         Idle       = 0x01,
  60.         Stopped    = 0x02,
  61.         Processing = 0x03,
  62.         Unknown    = 0x04,
  63.         Rejecting  = 0x08,
  64.         StateMask  = 0x07
  65.     };
  66.     enum PrinterCap {
  67.         CapBW       = 0x0001,
  68.         CapColor    = 0x0002,
  69.         CapDuplex   = 0x0004,
  70.         CapStaple   = 0x0008,
  71.         CapCopies   = 0x0010,
  72.         CapCollate  = 0x0020,
  73.         CapPunch    = 0x0040,
  74.         CapCover    = 0x0080,
  75.         CapBind     = 0x0100,
  76.         CapSort     = 0x0200,
  77.         CapSmall    = 0x0400,
  78.         CapMedium   = 0x0800,
  79.         CapLarge    = 0x1000,
  80.         CapVariable = 0x2000
  81.     };
  82.  
  83.     // constructor functions
  84.     KMPrinter();
  85.     KMPrinter(const KMPrinter& p);
  86.     ~KMPrinter();
  87.     void copy(const KMPrinter& p);
  88.  
  89.  
  90.     // inline access functions
  91.     const QString& name() const        { return m_name; }
  92.     void setName(const QString& s)        { m_name = s; if (m_printername.isEmpty()) m_printername = s; }
  93.     const QString& printerName() const    { return m_printername; }
  94.     void setPrinterName(const QString& s)    { m_printername = s; if (m_name.isEmpty()) m_name = s; }
  95.     const QString& instanceName() const    { return m_instancename; }
  96.     void setInstanceName(const QString& s)    { m_instancename = s; }
  97.     int type() const             { return m_type; }
  98.     void setType(int t)             { m_type = t; }
  99.     void addType(int t)             { m_type |= t; }
  100.     PrinterState state(bool complete = false) const         { return PrinterState(m_state & (complete ? ~0x0 : StateMask)); }
  101.     QString stateString() const;
  102.     void setState(PrinterState s)         { m_state = PrinterState((m_state & ~StateMask) | s); }
  103.     bool acceptJobs() const            { return !(m_state & Rejecting); }
  104.     void setAcceptJobs(bool on)        { m_state = PrinterState((m_state & StateMask) | (on ? 0 : Rejecting)); }
  105.     const QString& device() const         { return m_device; }
  106.     QString deviceProtocol() const;
  107.     void setDevice(const QString& d)         { m_device = d; }
  108.     const QStringList& members() const    { return m_members; }
  109.     void setMembers(const QStringList& l)    { m_members = l; }
  110.     void addMember(const QString& s)    { m_members.append(s); }
  111.     const QString& description() const     { return m_description; }
  112.     void setDescription(const QString& s)     { m_description = s; }
  113.     const QString& location() const     { return m_location; }
  114.     void setLocation(const QString& s)     { m_location = s; }
  115.     const KURL& uri() const         { return m_uri; }
  116.     void setUri(const KURL& u)         { m_uri = u; }
  117.     const QString& manufacturer() const    { return m_manufacturer; }
  118.     void setManufacturer(const QString&s )    { m_manufacturer = s; }
  119.     const QString& model() const        { return m_model; }
  120.     void setModel(const QString& s)        { m_model = s; }
  121.     const QString& driverInfo() const    { return m_driverinfo; }
  122.     void setDriverInfo(const QString& s)    { m_driverinfo = s; }
  123.     int printerCap() const              { return m_printercap; }
  124.     void setPrinterCap( int c )         { m_printercap = c; }
  125.     void addPrinterCap( int c )         { m_printercap |= c; }
  126.  
  127.     // some useful functions
  128.     bool isClass(bool useImplicit = true) const    { return ((m_type & KMPrinter::Class) || (useImplicit && isImplicit())); }
  129.     bool isImplicit() const                { return (m_type & KMPrinter::Implicit); }
  130.     bool isPrinter() const                { return (m_type & KMPrinter::Printer); }
  131.     bool isRemote() const                { return (m_type & KMPrinter::Remote); }
  132.     bool isLocal() const                { return !isRemote(); }
  133.     bool isVirtual() const                { return (m_type & KMPrinter::Virtual); }
  134.     bool isValid() const                { return !(m_type & KMPrinter::Invalid); }
  135.     bool isSpecial() const                { return (m_type & KMPrinter::Special); }
  136.  
  137.     // misc
  138.     KMDBEntry* dbEntry() const    { return m_dbentry; }
  139.     void setDbEntry(KMDBEntry *e)    { m_dbentry = e; }
  140.     QString pixmap();
  141.     void setPixmap(const QString& s)    { m_pixmap = s; }
  142.     bool isHardDefault() const    { return m_harddefault; }
  143.     void setHardDefault(bool on)    { m_harddefault = on; }
  144.     bool isSoftDefault() const    { return m_softdefault; }
  145.     void setSoftDefault(bool on)    { m_softdefault = on; }
  146.     bool ownSoftDefault() const    { return m_ownsoftdefault; }
  147.     void setOwnSoftDefault(bool on)    { m_ownsoftdefault = on; }
  148.     static int compare(KMPrinter *p1, KMPrinter *p2);
  149.     const QString& option(const QString& key) const         { return m_options[key]; }
  150.     bool hasOption(const QString& key) const             { return m_options.contains(key); }
  151.     void setOption(const QString& key, const QString& value)    { if (!key.isEmpty()) m_options[key] = value; }
  152.     void removeOption(const QString& key)                 { m_options.remove(key); }
  153.     QMap<QString,QString> options() const                 { return m_options; }
  154.     void setOptions(const QMap<QString,QString>& opts)        { m_options = opts; }
  155.     DrMain* driver() const                         { return m_driver; }
  156.     void setDriver(DrMain*);
  157.     DrMain* takeDriver();
  158.  
  159.     // configure an existing KPrinter object
  160.     bool autoConfigure(KPrinter *prt, QWidget *parent = 0);
  161.  
  162.     // default options
  163.     const QString& defaultOption(const QString& key) const         { return m_defaultoptions[key]; }
  164.     void setDefaultOption(const QString& key, const QString& value)    { if (!key.isEmpty()) m_defaultoptions[key] = value; }
  165.     QMap<QString,QString> defaultOptions() const             { return m_defaultoptions; }
  166.     void setDefaultOptions(const QMap<QString,QString>& opts)    { m_defaultoptions = opts; }
  167.     // edited options
  168.     const QString& editedOption(const QString& key) const         { return m_editedoptions[key]; }
  169.     void setEditedOption(const QString& key, const QString& value)    { if (!key.isEmpty()) m_editedoptions[key] = value; }
  170.     QMap<QString,QString> editedOptions() const             { return m_editedoptions; }
  171.     void setEditedOptions(const QMap<QString,QString>& opts)    { m_editedoptions = opts; }
  172.     // edited flag
  173.     bool isEdited() const     { return m_isedited; }
  174.     void setEdited(bool on)    { m_isedited = on; }
  175.  
  176.  
  177. protected:
  178.     // mandantory information
  179.     QString        m_name;        // identification name
  180.     QString        m_printername;    // real printer name
  181.     QString        m_instancename;    // instance name (human-readable)
  182.     int        m_type;        // printer type (any PrinterType flag OR-ed together)
  183.     PrinterState    m_state;    // printer state
  184.     /**
  185.      * Represent the device as a string, to provide native
  186.      * support for exotic devices. Conversion to URL is done
  187.      * only when really needed
  188.      */
  189.     QString        m_device;    // printer device
  190.  
  191.     // class specific information
  192.     QStringList    m_members;    // members of the class
  193.  
  194.     // other useful information that should be completed by manager on demand
  195.     QString        m_description;    // short description, comment
  196.     QString        m_location;    // printer location
  197.     KURL        m_uri;        // URI printer identification
  198.     QString        m_manufacturer;    // printer manufacturer (driver)
  199.     QString        m_model;    // printer model (driver)
  200.     QString        m_driverinfo;    // short driver info (ex: nick name in PPD)
  201.  
  202.     // DB driver entry (used when creating a printer). Internal use only !!!
  203.     KMDBEntry    *m_dbentry;
  204.     DrMain        *m_driver;
  205.     QString        m_pixmap;
  206.  
  207.     // default flags
  208.     bool        m_harddefault;
  209.     bool        m_softdefault;
  210.         bool            m_ownsoftdefault;
  211.  
  212.     // other options (for any use)
  213.     QMap<QString,QString>    m_options;
  214.  
  215.     // options used for instances, and print library. These options are not
  216.     // overwritten when copying from another KMPrinter object. This allows to
  217.     // to keep the user settings through an application session. The difference
  218.     // between "default" and "edited" can be used for option saving (only save
  219.     // the options corresponding to current edited printer).
  220.     QMap<QString,QString>    m_defaultoptions;
  221.     QMap<QString,QString>    m_editedoptions;
  222.     bool            m_isedited;
  223.  
  224.     // printer capabilities (based on CUPS model)
  225.     int m_printercap;
  226. };
  227.  
  228. class KMPrinterList : public QPtrList<KMPrinter>
  229. {
  230. public:
  231.     KMPrinterList() : QPtrList<KMPrinter>() {}
  232.     virtual int compareItems(QPtrCollection::Item i1, QPtrCollection::Item i2)
  233.     { return KMPrinter::compare((KMPrinter*)i1, (KMPrinter*)i2); }
  234. };
  235.  
  236. #endif
  237.